package com.yusp75.myexam.ui.setting

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.yusp75.myexam.com.yusp75.myexam.di.PrefManager
import com.yusp75.myexam.di.DataHolder

class SettingViewModel(
    private val holder: DataHolder,
    private val prefs: PrefManager
) : ViewModel() {

    var numOfChoice = MutableLiveData<Int>().apply {
        value = prefs.numOfChoice
    }
    var numOfJudge = MutableLiveData<Int>().apply {
        value = prefs.numOfJudge
    }

    var choiceHint = MutableLiveData<String>().apply {
        value = "5..${holder.choiceQuestionNum}"
    }

    var judgeHint = MutableLiveData<String>().apply {
        value = "5..${holder.judgeQuestionNum}"
    }

    fun getNumOfChoice(): Int {
        return holder.choiceQuestionNum
    }

    fun getNumOfJudge(): Int {
        return holder.judgeQuestionNum
    }

    fun saveNumChoice(value: Int, min: Int = 5, max: Int = holder.choiceQuestionNum) {
        require(value in min..max) { "value($value) must be between $min and $max" }
        prefs.numOfChoice = value
    }


    fun saveNumJudge(value: Int, min: Int = 5, max: Int = holder.judgeQuestionNum) {
        require(value in min..max) { "value($value) must be between $min and $max" }
        prefs.numOfJudge = value
    }
}